package nancal.mp.service.git

import nancal.mp.db.mongo.GitServerTypeEnum
import nancal.mp.db.mongo.entity.dev.GitServer
import nancal.mp.model.git.GitBranchCommitModel
import nancal.mp.model.git.GitOrgItem
import nancal.mp.service.git.impl.GitEaService
import nancal.mp.service.git.impl.GitLabService
import nbcp.base.comm.ApiResult
import nbcp.base.comm.ListResult
import nbcp.base.db.IdName
import nbcp.base.utils.SpringUtil

interface GitApiService {
    companion object {
        fun getInstance(type: GitServerTypeEnum): GitApiService {
            return when (type) {
                GitServerTypeEnum.Gitea -> SpringUtil.getBean<GitEaService>()
                GitServerTypeEnum.Gitlab -> SpringUtil.getBean<GitLabService>()
            }
        }
    }

    fun getOrgs(gitServer: GitServer): ListResult<IdName>;
    fun getRepos(gitServer: GitServer, org: String): ListResult<GitOrgItem>;
    fun getBranchCommitInfo(
        gitHost: String,
        accessToken:String,
        group: String,
        repo: String,
        branch: String
    ): ApiResult<GitBranchCommitModel>;

    fun getBranches(
        gitHost: String,
        accessToken:String,
        owner: String,
        repo: String,
        take: Int
    ): ListResult<GitBranchCommitModel>;


    fun existsFile(
        gitHost: String,
        accessToken:String,
        owner: String,
        repo: String,
        branchName: String,
        path: String
    ): ApiResult<Boolean>


    fun getRawFile(
        gitHost: String,
        accessToken:String,
        owner: String,
        repo: String,
        branch: String,
        fileName: String
    ): ApiResult<ByteArray>;
}